package cn.schoolwow.workflow.module.instance.action.service;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.entity.WorkFlowInstance;
import com.alibaba.fastjson.JSONObject;

public class UpdateWorkFlowInstanceContextDataServiceFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        DAO dao = flowContext.checkInstanceData(DAO.class);
        long workFlowInstanceId = (long) flowContext.checkData("workFlowInstanceId");
        JSONObject contextData = flowContext.checkData("contextData", JSONObject.class);

        dao.addRecordString("更新工作流上下文数据");
        dao.query(WorkFlowInstance.class)
                .addQuery("id", workFlowInstanceId)
                .addUpdate("contextData", contextData)
                .execute()
                .update();
    }

    @Override
    public String name() {
        return "更新工作流实例上下文数据服务流程";
    }
}
